package com.demo.chattest.chat;

import android.os.Bundle;
import android.support.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.demo.chattest.R;
import com.demo.chattest.bean.MessageInfo;

import java.util.List;

/**
 * @Package com.demo.chattest.chat
 * @Describe class描述
 * @Author wugx
 * @Date 2020-09-25
 */
public class SendImageItemProvider extends BaseItemProvider<MessageInfo, BaseViewHolder> {
    @Override
    public int viewType() {
        return 12;
    }

    @Override
    public int layout() {
        return R.layout.item_send_img;
    }

    @Override
    public void convert(@NonNull BaseViewHolder helper, MessageInfo data, int position) {
        helper.addOnClickListener(R.id.iv_headImg,R.id.iv_img);
        helper.setText(R.id.tv_name, data.getFromUName());
        helper.setText(R.id.tv_date, data.getTime() + "");
        helper.setVisible(R.id.ll_d_n, data.getTargetType() != 3);
        Glide.with(mContext).load(data.getFromHeadImg()).into(helper.getImageView(R.id.iv_headImg));
        //状态 0：发送 1：成功  2：失败
        helper.setVisible(R.id.pb_loading, data.getStatus() == 0);
        Glide.with(mContext).load(data.getImgThumbUrl()).placeholder(R.drawable.chat_bg_img_default).error(R.drawable.chat_img_not_found).transition(DrawableTransitionOptions.withCrossFade()).override(360,300).into(helper.getImageView(R.id.iv_img));
    }

    @Override
    public void convertPayloads(@NonNull BaseViewHolder helper, MessageInfo data, int position, @NonNull List<Object> payloads) {
        super.convertPayloads(helper, data, position, payloads);
        if (payloads.get(0) instanceof Bundle) {
            Bundle bundle = (Bundle) payloads.get(0);
            boolean state = bundle.getBoolean("",false);
            if (state){
                helper.setVisible(R.id.pb_loading, data.getStatus() == 0);
            }
        }
    }
}
